package com.appkubes.mall.admin.application.goods.stage;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api("商品分期设置")
@RestController
@RequestMapping("/sass_admin/Sgoodsstage")
public class GoodsStageController extends BaseController {

    @Autowired
    GoodsStageService stageService;

    @ApiOperation("更新分期设置")
    @PostMapping("/update")
    public Response update(@RequestParam(defaultValue = "") String stages, @RequestParam(defaultValue = "") String goodKey) {
        JSONArray jsonArray = JSON.parseArray(stages);
        stageService.insertAll(jsonArray, goodKey);
        return Response.success();
    }

    @ApiOperation("获取商品分期配置")
    @PostMapping("/get")
    public Response get(@RequestParam(defaultValue = "") String goodKey) {
        return Response.success(stageService.queryById(goodKey));
    }
}
